package com.tiniplanet.webgate.entity;

import static javax.persistence.GenerationType.IDENTITY;

import java.sql.Blob;
import java.sql.Date;
import java.sql.SQLException;
import java.sql.Time;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;

@Entity
@Table(name = "HR_WEB_TINTUC")
public class News extends AbstractModel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3266165296050231861L;

	private long id;
	private String title;
	private String summary;
	private Blob content;
	private Date publishDate;
	private Time publishTime;
	private String author;
	private Blob contentHTML;


	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "TIN_ID", unique = true, nullable = false, length = 10)
	/**
	 * @return the id
	 */
	public long getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(long id) {
		this.id = id;
	}

	/**
	 * @return the title
	 */
	@Column(name = "TIN_TIEUDE", nullable = false, length = 85)
	public String getTitle() {
		return title;
	}

	/**
	 * @param title
	 *            the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * @return the summary
	 */
	@Column(name = "TIN_TOMTAT", nullable = false, length = 1024)
	public String getSummary() {
		return summary;
	}

	/**
	 * @param summary
	 *            the summary to set
	 */
	public void setSummary(String summary) {
		this.summary = summary;
	}

	/**
	 * @return the content
	 */

	@Column(name = "TIN_NOIDUNG", nullable = false)
	@Lob
	public Blob getContent() {
		return content;
	}

	/**
	 * @param content
	 *            the content to set
	 */

	public void setContent(Blob content) {
		this.content = content;
	}

	/**
	 * @return the publishDate
	 */
	@Column(name = "TIN_NGAYDANG", nullable = false)
	public Date getPublishDate() {
		return publishDate;
	}

	/**
	 * @param publishDate
	 *            the publishDate to set
	 */
	public void setPublishDate(Date publishDate) {
		this.publishDate = publishDate;
	}

	/**
	 * @return the publishTime
	 */
	@Column(name = "TIN_GIODANG", nullable = false)
	public Time getPublishTime() {
		return publishTime;
	}

	/**
	 * @param publishTime
	 *            the publishTime to set
	 */
	public void setPublishTime(Time publishTime) {
		this.publishTime = publishTime;
	}

	/**
	 * @return the author
	 */
	@Column(name = "TIN_NGUOIDANG", nullable = false)
	public String getAuthor() {
		return author;
	}

	/**
	 * @param author
	 *            the author to set
	 */
	public void setAuthor(String author) {
		this.author = author;
	}

	/**
	 * @return the contentHTML
	 */
	@Column(name = "TIN_MAHOA_HTML", nullable = false)
	@Lob
	public Blob getContentHTML() {
		return contentHTML;
	}

	/**
	 * @param contentHTML
	 *            the contentHTML to set
	 */
	public void setContentHTML(Blob contentHTML) {
		this.contentHTML = contentHTML;
	}

	/**
	 * @return the strContent
	 */
	public String strContent() {
		byte[] bdata = null;
		try {
			bdata = this.content.getBytes(1,
					(int) this.content.length());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return new String(bdata);
	}

	
	/**
	 * @return the strContentHTML
	 */
	public String strContentHTML() {		
		
		byte[] bdata = null;
		try {
			bdata = this.contentHTML.getBytes(1,
					(int) this.contentHTML.length());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return new String(bdata);
	}	
}
